<template>
  <div class="admin-layout">
    <!-- 顶部导航栏 -->
    <el-header class="admin-header">
      <div class="header-left">
        <h2>健身活动管理系统</h2>
      </div>
      <div class="header-right">
        <span class="welcome-text">欢迎，{{ userInfo.username }}</span>
        <el-button type="text" @click="handleLogout">退出登录</el-button>
      </div>
    </el-header>
    <!-- 侧边栏 -->
    <el-container class="admin-container">
      <el-aside width="200px" class="admin-sidebar">
        <el-menu
          :default-active="$route.path"
          router
          background-color="#2c3e50"
          text-color="#fff"
          active-text-color="#409EFF"
        >
          <el-menu-item index="/admin/dashboard">
            <el-icon><DataBoard /></el-icon>
            <span>仪表盘</span>
          </el-menu-item>
          <el-menu-item index="/admin/activities">
            <el-icon><Calendar /></el-icon>
            <span>活动管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/bookings">
            <el-icon><List /></el-icon>
            <span>预约管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/users">
            <el-icon><User /></el-icon>
            <span>用户管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/venues">
            <i class="el-icon-office-building"></i>
            <span>场馆管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/coaches">
            <i class="el-icon-user"></i>
            <span>教练管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      
      <!-- 主内容区域 -->
      <el-main class="admin-main">
        <router-view />
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { DataBoard, Calendar, List, User } from '@element-plus/icons-vue'

const router = useRouter()

// 获取用户信息
const userInfo = computed(() => {
  return JSON.parse(localStorage.getItem('userInfo') || '{}')
})

// 退出登录
const handleLogout = async () => {
  try {
    await ElMessageBox.confirm('确定要退出登录吗？', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    
    // 清除本地存储
    localStorage.removeItem('token')
    localStorage.removeItem('userInfo')
    
    ElMessage.success('退出登录成功')
    router.push('/login')
  } catch (error) {
    // 用户取消退出
  }
}
</script>

<style scoped>
.admin-layout {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.admin-header {
  background-color: #2c3e50;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-left h2 {
  margin: 0;
  font-size: 1.5em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 15px;
}

.welcome-text {
  font-size: 14px;
}

.admin-container {
  height: calc(100vh - 60px);
}

.admin-sidebar {
  background-color: #2c3e50;
}

.admin-sidebar :deep(.el-menu) {
  border-right: none;
}

.admin-sidebar :deep(.el-menu-item) {
  height: 50px;
  line-height: 50px;
}

.admin-sidebar :deep(.el-menu-item:hover) {
  background-color: #34495e;
}

.admin-sidebar :deep(.el-menu-item.is-active) {
  background-color: #409EFF;
}

.admin-main {
  padding: 20px;
  background-color: white;
  margin: 10px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
</style> 